Table of Contents Previous Section

Debugging

WebScript includes methods that are useful for debugging: logWithFormat:, and several trace methods. Using these methods in conjunction with launching your application from the command line provides you with a fairly complete picture of your running application.

logWithFormat:

The WebScript method logWithFormat: writes a formatted string to stderr. Like the printf() function in C, this method takes a format string and optionally, a variable number of additional arguments. For example, the following code excerpt prints the string: "The value of myString is Elvis":

myString = @"Elvis";
[self logWithFormat:@"The value of myString is %@", myString];

When this code is parsed, the value of myString is substituted for the conversion specification %@. The conversion character @ indicates that the data type of the variable being substituted is an object (that is, of the id data type).

Note that because WebScript only supports the data type id, the conversion specification you use must always be %@. Unlike printf(), you can't supply conversion specifications for primitive C data types such as %d, %s, %f, and so on.

To see the output from logWithFormat: statements, you have to run your application from a command shell as follows:

  1. cd to /NextLibrary/WebObjects/Executables.

  2. Type the following in the command shell:
    DefaultApp MyApp
    

    where MyApp is the name of your application.

  3. In your browser, open the URL you'd normally use to launch your application:
    http://myHost/cgi-bin/WebObjects/MyApp
    

    As your application runs, the output from logWithFormat: and other information about your application is displayed in the command shell window.

Trace Methods

WebScript provides trace methods that log different kinds of information about your running application. The trace methods are described in the following table:

Method  		Description
________________________________________________________________________

trace:			Enables all tracing. 

traceAssignments:	Logs information about all assignment statements.

traceStatements:	Logs information about all statements.

traceScriptedMessages:	Logs information when an application enters 
			and exits a scripted method.
________________________________________________________________________

To use any of the trace methods, you must run your application from a command shell, as described above.

You use the trace methods in either the awake or the willPrepareForRequest:inContext: method:

- awake {
  [self traceAssignments:YES];
  [self traceScriptedMessages:YES];
}

Table of Contents Next Section